pixelcache: Don't have a style context argument
authorBenjamin Otte <otte@redhat.com>
Thu, 25 Feb 2016 15:14:37 +0000 (16:14 +0100)
committerBenjamin Otte <otte@redhat.com>
Thu, 25 Feb 2016 15:52:58 +0000 (16:52 +0100)
That would imply the pixelcache monitors the style context for changes
and it doesn't do that.

Its only use case was opacity checks, so add
gtk_pixel_cache_se_is_opaque() instead.

gtk/gtkpixelcache.c
gtk/gtkpixelcacheprivate.h
gtk/gtktextview.c
gtk/gtkviewport.c

index 34a710b6ce8c2a330d8245d9ebf04a30e0a5a9cc..9448401b9eb142b2ccf3414b1e2b614bb520dbc8 100644 (file)
@@ -47,15 +47,13 @@ struct _GtkPixelCache {
   /* may be null if not dirty */
   cairo_region_t *surface_dirty;
 
-  /* background tracking for rgb/rgba */
-  GtkStyleContext *style_context;
-
   guint timeout_tag;
 
   guint extra_width;
   guint extra_height;
 
   guint always_cache : 1;
+  guint is_opaque : 1;
 };
 
 GtkPixelCache *
@@ -93,8 +91,6 @@ _gtk_pixel_cache_free (GtkPixelCache *cache)
   if (cache->surface_dirty != NULL)
     cairo_region_destroy (cache->surface_dirty);
 
-  g_clear_object (&cache->style_context);
-
   g_free (cache);
 }
 
@@ -197,10 +193,10 @@ _gtk_pixel_cache_create_surface_if_needed (GtkPixelCache         *cache,
   content = cache->content;
   if (!content)
     {
-      content = CAIRO_CONTENT_COLOR_ALPHA;
-      if (cache->style_context &&
-          gtk_css_style_render_background_is_opaque (gtk_style_context_lookup_style (cache->style_context)))
+      if (cache->is_opaque)
         content = CAIRO_CONTENT_COLOR;
+      else
+        content = CAIRO_CONTENT_COLOR_ALPHA;
     }
 
   surface_w = view_rect->width;
@@ -504,9 +500,12 @@ _gtk_pixel_cache_set_always_cache (GtkPixelCache *cache,
 }
 
 void
-_gtk_pixel_cache_set_style_context (GtkPixelCache   *cache,
-                                    GtkStyleContext *style_context)
+gtk_pixel_cache_set_is_opaque (GtkPixelCache *cache,
+                               gboolean       is_opaque)
 {
-  if (g_set_object (&cache->style_context, style_context))
-    _gtk_pixel_cache_invalidate (cache, NULL);
+  if (cache->is_opaque == is_opaque)
+    return;
+
+  cache->is_opaque = is_opaque;
+  _gtk_pixel_cache_invalidate (cache, NULL);
 }
index 264717aab80a5badcb51ecad7f667383f1d845ff..6ab3090a174311b5c55a2345628c8f89a834fbc3 100644 (file)
@@ -54,8 +54,8 @@ void           _gtk_pixel_cache_set_content      (GtkPixelCache         *cache,
 gboolean       _gtk_pixel_cache_get_always_cache (GtkPixelCache         *cache);
 void           _gtk_pixel_cache_set_always_cache (GtkPixelCache         *cache,
                                                   gboolean               always_cache);
-void           _gtk_pixel_cache_set_style_context(GtkPixelCache         *cache,
-                                                  GtkStyleContext       *style_context);
+void           gtk_pixel_cache_set_is_opaque     (GtkPixelCache         *cache,
+                                                  gboolean               is_opaque);
 
 
 G_END_DECLS
index b79a892badb26aa8e7164b88b8a8a0cf5ad7fbc9..3424c4756b71751a116769104d53b27602d19eea 100644 (file)
@@ -37,6 +37,7 @@
 #include "gtkmarshalers.h"
 #include "gtkmenu.h"
 #include "gtkmenuitem.h"
+#include "gtkrenderbackgroundprivate.h"
 #include "gtkseparatormenuitem.h"
 #include "gtksettings.h"
 #include "gtkselectionprivate.h"
@@ -51,7 +52,6 @@
 #include "gtkscrollable.h"
 #include "gtktypebuiltins.h"
 #include "gtktexthandleprivate.h"
-#include "gtkstylecontextprivate.h"
 #include "gtkcssstylepropertyprivate.h"
 #include "gtkpopover.h"
 #include "gtktoolbar.h"
@@ -1685,7 +1685,6 @@ gtk_text_view_init (GtkTextView *text_view)
 
   context = gtk_widget_get_style_context (GTK_WIDGET (text_view));
   gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
-  _gtk_pixel_cache_set_style_context (priv->pixel_cache, context);
 
   /* Set up default style */
   priv->wrap_mode = GTK_WRAP_NONE;
@@ -9775,10 +9774,18 @@ node_style_changed_cb (GtkCssNode        *node,
                        GtkCssStyleChange *change,
                        GtkWidget         *widget)
 {
+  GtkTextViewPrivate *priv = GTK_TEXT_VIEW (widget)->priv;
+
   if (gtk_css_style_change_affects (change, GTK_CSS_AFFECTS_SIZE | GTK_CSS_AFFECTS_CLIP))
     gtk_widget_queue_resize (widget);
   else
     gtk_widget_queue_draw (widget);
+
+  if (node == priv->text_window->css_node)
+    {
+      GtkCssStyle *style = gtk_css_style_change_get_new_style (change);
+      gtk_pixel_cache_set_is_opaque (priv->pixel_cache, gtk_css_style_render_background_is_opaque (style));
+    }
 }
 
 static void
index 368374c5e3d4d11cd5e1ac450793f6c80c732198..088951487e5ca81ad3e313d769a9af083f42bf78 100644 (file)
@@ -33,7 +33,8 @@
 #include "gtkpixelcacheprivate.h"
 #include "gtkprivate.h"
 #include "gtkscrollable.h"
-#include "gtkrender.h"
+#include "gtkrenderbackgroundprivate.h"
+#include "gtkstylecontextprivate.h"
 #include "gtktypebuiltins.h"
 #include "gtkwidgetprivate.h"
 
@@ -937,6 +938,18 @@ gtk_viewport_draw (GtkWidget *widget,
   return FALSE;
 }
 
+static void
+gtk_viewport_update_pixelcache_opacity (GtkWidget   *child,
+                                        GtkViewport *viewport)
+{
+  GtkViewportPrivate *priv = viewport->priv;
+
+  gtk_pixel_cache_set_is_opaque (priv->pixel_cache,
+                                 gtk_css_style_render_background_is_opaque (
+                                   gtk_style_context_lookup_style (
+                                     gtk_widget_get_style_context (child))));
+}
+
 static void
 gtk_viewport_remove (GtkContainer *container,
                     GtkWidget    *child)
@@ -944,10 +957,14 @@ gtk_viewport_remove (GtkContainer *container,
   GtkViewport *viewport = GTK_VIEWPORT (container);
   GtkViewportPrivate *priv = viewport->priv;
 
-  GTK_CONTAINER_CLASS (gtk_viewport_parent_class)->remove (container, child);
+  if (g_signal_handlers_disconnect_by_func (child, gtk_viewport_update_pixelcache_opacity, viewport) != 1)
+    {
+      g_assert_not_reached ();
+    }
 
-  _gtk_pixel_cache_set_style_context (priv->pixel_cache, NULL);
+  GTK_CONTAINER_CLASS (gtk_viewport_parent_class)->remove (container, child);
 
+  gtk_pixel_cache_set_is_opaque (priv->pixel_cache, FALSE);
 }
 
 static void
@@ -961,11 +978,11 @@ gtk_viewport_add (GtkContainer *container,
   g_return_if_fail (gtk_bin_get_child (bin) == NULL);
 
   gtk_widget_set_parent_window (child, priv->bin_window);
-
-  _gtk_pixel_cache_set_style_context (priv->pixel_cache,
-                                      gtk_widget_get_style_context (child));
-
+  
   GTK_CONTAINER_CLASS (gtk_viewport_parent_class)->add (container, child);
+
+  g_signal_connect (child, "style-updated", G_CALLBACK (gtk_viewport_update_pixelcache_opacity), viewport);
+  gtk_viewport_update_pixelcache_opacity (child, viewport);
 }
 
 static void